<?php

class Admin_Model_Userrole extends Zend_Db_Table_Abstract
{
    protected $_name = 'user_role';
    public $_configGame;
    public function __construct($partner)
    {
        $configGame     = new Zend_Config_Ini(CONFIG_PATH . '/application.ini', APPLICATION_ENV);
        $this->_configGame = $configGame;
        if(!isset($configGame->partner->$partner)){
            die('Config db not found!!!');
        }
    	$db = $configGame->partner->$partner;
		$db = Zend_Db::factory($db->adapter, $db->params);
        $this->_setAdapter($db);
    }
    public function getDataByUserId ($userId){
    	$query = $this->select()
                        ->from($this->_name,array('roleId'))
                        ->where('userId = ?',(int)$userId);
        return $this->fetchAll($query);
    }
    public function addMultiData($userRole){
        $sql = 'INSERT INTO '.$this->_name.' (userId, roleId) VALUES '. implode(',', $userRole);
            
		$stmt = $this->getAdapter()->prepare($sql);
		$stmt->execute();
    }
    public function deleteData($userId){
        return $this->delete('userId = ' . (int) $userId);  
    }
    public function deleteDataByRoleId($userId){
        return $this->delete('roleId = '.(int) $roleId);
    }
}

